package digitSum;

public class Solution {
    public String digitSum(String s, int k) {
        if(k>=s.length()) return s;
        StringBuilder sb = new StringBuilder();
        for (int i = 0; i < s.length(); i+=k) {
            if(i+k<=s.length()) {
                sb.append(add(s.substring(i,i+k)));
            } else {
                sb.append(s.substring(i,s.length()));
            }
        }
        return digitSum(sb.toString(),k);
    }
    private int add(String s) {
        int ans = 0;
        for (int i = 0; i < s.length(); i++) {
            ans+=s.charAt(i)-'0';
        }
        return ans;
    }
}
